package com.ymatou.iapi.prodstock.testcase;

import com.ymatou.iapi.prodstock.parameter.FreezeAllocateStockBean;
import com.ymatou.iapi.prodstock.parameter.FreezeCatalogInfo;
import com.ymatou.iapi.prodstock.parameter.FreezeProductResult;
import com.ymatou.iapi.prodstock.service.FreezeAllocateStockCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductActivityStockWapper;
import com.ymttest.database.sqlwapper.YmtProductFreezeStockWapper;
import com.ymttest.utils.EnvSetup;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
*冻结库存
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_FreezeAllocateStock{
	private static FreezeAllocateStockBean freezeallocatestockBean;
	private static FreezeAllocateStockCall freezeallocatestockCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static ArrayList<FreezeCatalogInfo> FreezeCatalogList;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("冻结库存");
	}

	@Before
	public void caseUp() {
		freezeallocatestockBean=new FreezeAllocateStockBean();
		freezeallocatestockCall=new FreezeAllocateStockCall();
		FreezeCatalogList = new ArrayList<FreezeCatalogInfo>();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(freezeallocatestockCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	/**
	 * 商品参与活动，规格无论参不参与活动，都会进入冻结表中
	 */
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_FreezeAllocateStock_001() {
		Logger.start(true,"活动商品申请冻结，添加冻结表（非sku商品）");
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			String freezeId = "JD18628";
			freezeallocatestockBean.setActivityId(activityId);
			freezeallocatestockBean.setFreezeId(freezeId);
			freezeallocatestockBean.setFreezeType(0);
			freezeallocatestockBean.setIsFbxProduct(false);
			freezeallocatestockBean.setProductInActivityId(Integer.valueOf(aids.get(0)));
			freezeallocatestockBean.setProductID(productId);
			freezeallocatestockBean.setStoreType(-1);
			freezeallocatestockBean.setUserID(sellerId);
			FreezeCatalogInfo freezeCatalogInfo = new FreezeCatalogInfo();
			freezeCatalogInfo.setCatalogId(catalogs.get(0));
			freezeCatalogInfo.setFreezeNum(100);
			freezeCatalogInfo.setSku(null);
			FreezeCatalogList.add(freezeCatalogInfo);
			freezeallocatestockBean.setFreezeCatalogList(FreezeCatalogList);
			freezeallocatestockCall.setData(freezeallocatestockBean);
			freezeallocatestockCall.callService();
			String Code = freezeallocatestockCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			
			freezeallocatestockCall.getResults().forEach(pp->{
				Logger.verifyEquals(activityId, pp.getActivityId(), "验证活动编号");
				Logger.verifyEquals(productId, pp.getProductId(), "验证商品编号");
				Logger.verifyEquals(catalogs.get(0), pp.getCatalogId(), "验证规格编号");
				Logger.verifyEquals(freezeId, pp.getFreezeId(), "验证冻结编号");
				Logger.verifyEquals(aids.get(0), pp.getProductInActivityId().toString(), "验证商品在活动中的编号");
			});
			
			//验证规格库存
			Integer num = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Integer activityStock = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(catalogNum-freezeCatalogInfo.getFreezeNum()-activityStock, num, "验证规格库存");
			//验证冻结表库存
			Integer freezeNum = new YmtProductFreezeStockWapper().selectByProductId(productId).get(0).getFreezeNum();
			Logger.verifyEquals(freezeCatalogInfo.getFreezeNum(),freezeNum, "验证冻结表库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_FreezeAllocateStock_002() {
		Logger.start(true,"fpx活动商品申请冻结，添加冻结表（sku商品）");
		try {
			//创建商品
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			String freezeId = "JD18628";
			freezeallocatestockBean.setActivityId(activityId);
			freezeallocatestockBean.setFreezeId(freezeId);
			freezeallocatestockBean.setFreezeType(0);
			freezeallocatestockBean.setIsFbxProduct(false);
			freezeallocatestockBean.setProductInActivityId(Integer.valueOf(aids.get(0)));
			freezeallocatestockBean.setProductID(productId);
			freezeallocatestockBean.setStoreType(-1);
			freezeallocatestockBean.setUserID(sellerId);
			FreezeCatalogInfo freezeCatalogInfo = new FreezeCatalogInfo();
			freezeCatalogInfo.setCatalogId(catalogs.get(0));
			freezeCatalogInfo.setFreezeNum(100);
			freezeCatalogInfo.setSku("E1HRBB30_70091");
			FreezeCatalogList.add(freezeCatalogInfo);
			freezeallocatestockBean.setFreezeCatalogList(FreezeCatalogList);
			freezeallocatestockCall.setData(freezeallocatestockBean);
			freezeallocatestockCall.callService();
			String Code = freezeallocatestockCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			
			freezeallocatestockCall.getResults().forEach(pp->{
				Logger.verifyEquals(activityId, pp.getActivityId(), "验证活动编号");
				Logger.verifyEquals(productId, pp.getProductId(), "验证商品编号");
				Logger.verifyEquals(catalogs.get(0), pp.getCatalogId(), "验证规格编号");
				Logger.verifyEquals(freezeId, pp.getFreezeId(), "验证冻结编号");
				Logger.verifyEquals(aids.get(0), pp.getProductInActivityId().toString(), "验证商品在活动中的编号");
			});
			
			//验证规格库存
			Integer num = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Integer activityStock = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(catalogNum-freezeCatalogInfo.getFreezeNum()-activityStock, num, "验证规格库存");
			//验证冻结表库存
			Integer freezeNum = new YmtProductFreezeStockWapper().selectByProductId(productId).get(0).getFreezeNum();
			Logger.verifyEquals(freezeCatalogInfo.getFreezeNum(),freezeNum, "验证冻结表库存");
			
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_FreezeAllocateStock_003() {
		Logger.start(true,"冻结商品再次申请冻结");
		try {
			/**
			 * 记录日志返回，数据库表不变
			 */
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			String freezeId = "JD18628";
			freezeallocatestockBean.setActivityId(activityId);
			freezeallocatestockBean.setFreezeId(freezeId);
			freezeallocatestockBean.setFreezeType(0);
			freezeallocatestockBean.setIsFbxProduct(false);
			freezeallocatestockBean.setProductInActivityId(Integer.valueOf(aids.get(0)));
			freezeallocatestockBean.setProductID(productId);
			freezeallocatestockBean.setStoreType(-1);
			freezeallocatestockBean.setUserID(sellerId);
			FreezeCatalogInfo freezeCatalogInfo = new FreezeCatalogInfo();
			freezeCatalogInfo.setCatalogId(catalogs.get(0));
			freezeCatalogInfo.setFreezeNum(100);
			freezeCatalogInfo.setSku("E1HRBB30_70091");
			FreezeCatalogList.add(freezeCatalogInfo);
			freezeallocatestockBean.setFreezeCatalogList(FreezeCatalogList);
			freezeallocatestockCall.setData(freezeallocatestockBean);
			freezeallocatestockCall.callService();
			freezeCatalogInfo.setFreezeNum(100);
			freezeallocatestockCall.callService();
			String Code = freezeallocatestockCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			
			//验证规格库存
			Integer num = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Integer activityStock = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(catalogNum-freezeCatalogInfo.getFreezeNum()-activityStock, num, "验证规格库存");
			//验证冻结表库存
			Integer freezeNum = new YmtProductFreezeStockWapper().selectByProductId(productId).get(0).getFreezeNum();
			Logger.verifyEquals(freezeCatalogInfo.getFreezeNum(),freezeNum, "验证冻结表库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_FreezeAllocateStock_004() {
		Logger.start(true,"冻结商品数量大于规格库存现有数量");
		try {
			/**
			 * 异常，规格扣除失败
			 */
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			String freezeId = "JD18628";
			freezeallocatestockBean.setActivityId(activityId);
			freezeallocatestockBean.setFreezeId(freezeId);
			freezeallocatestockBean.setFreezeType(0);
			freezeallocatestockBean.setIsFbxProduct(false);
			freezeallocatestockBean.setProductInActivityId(Integer.valueOf(aids.get(0)));
			freezeallocatestockBean.setProductID(productId);
			freezeallocatestockBean.setStoreType(-1);
			freezeallocatestockBean.setUserID(sellerId);
			FreezeCatalogInfo freezeCatalogInfo = new FreezeCatalogInfo();
			freezeCatalogInfo.setCatalogId(catalogs.get(0));
			freezeCatalogInfo.setFreezeNum(10000);
			freezeCatalogInfo.setSku(null);
			FreezeCatalogList.add(freezeCatalogInfo);
			freezeallocatestockBean.setFreezeCatalogList(FreezeCatalogList);
			freezeallocatestockCall.setData(freezeallocatestockBean);
			freezeallocatestockCall.callService();
			String Code = freezeallocatestockCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_FreezeAllocateStock_005() {
		Logger.start(true,"同一活动商品，不同规格冻结");
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			String freezeId = "JD18628";
			freezeallocatestockBean.setActivityId(activityId);
			freezeallocatestockBean.setFreezeId(freezeId);
			freezeallocatestockBean.setFreezeType(0);
			freezeallocatestockBean.setIsFbxProduct(false);
			freezeallocatestockBean.setProductInActivityId(Integer.valueOf(aids.get(0)));
			freezeallocatestockBean.setProductID(productId);
			freezeallocatestockBean.setStoreType(-1);
			freezeallocatestockBean.setUserID(sellerId);
			FreezeCatalogInfo freezeCatalogInfo1 = new FreezeCatalogInfo();
			freezeCatalogInfo1.setCatalogId(catalogs.get(0));
			freezeCatalogInfo1.setFreezeNum(100);
			freezeCatalogInfo1.setSku(null);
			FreezeCatalogInfo freezeCatalogInfo2 = new FreezeCatalogInfo();
			freezeCatalogInfo2.setCatalogId(catalogs.get(1));
			freezeCatalogInfo2.setFreezeNum(200);
			freezeCatalogInfo2.setSku(null);
			FreezeCatalogList.add(freezeCatalogInfo1);
			FreezeCatalogList.add(freezeCatalogInfo2);
			freezeallocatestockBean.setFreezeCatalogList(FreezeCatalogList);
			freezeallocatestockCall.setData(freezeallocatestockBean);
			freezeallocatestockCall.callService();
			String Code = freezeallocatestockCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			
			FreezeProductResult productResult1 = freezeallocatestockCall.getResults().get(0);
			Logger.verifyEquals(activityId, productResult1.getActivityId(), "验证活动编号");
			Logger.verifyEquals(productId, productResult1.getProductId(), "验证商品编号");
			Logger.verifyEquals(catalogs.get(0), productResult1.getCatalogId(), "验证规格编号");
			Logger.verifyEquals(freezeId, productResult1.getFreezeId(), "验证冻结编号");
			Logger.verifyEquals(aids.get(0), productResult1.getProductInActivityId().toString(), "验证商品在活动中的编号");
			FreezeProductResult productResult2 = freezeallocatestockCall.getResults().get(1);
			Logger.verifyEquals(activityId, productResult2.getActivityId(), "验证活动编号");
			Logger.verifyEquals(productId, productResult2.getProductId(), "验证商品编号");
			Logger.verifyEquals(catalogs.get(1), productResult2.getCatalogId(), "验证规格编号");
			Logger.verifyEquals(freezeId, productResult2.getFreezeId(), "验证冻结编号");
			Logger.verifyEquals(aids.get(0), productResult2.getProductInActivityId().toString(), "验证商品在活动中的编号");
			
			
			//验证规格库存
			Integer num1 = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Integer activityStock1 = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(catalogNum-freezeCatalogInfo1.getFreezeNum()-activityStock1, num1, "验证规格库存");
			
			Integer num2 = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(1).getiNum();
			Integer activityStock2 = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(1)).getIstocknum();
			Logger.verifyEquals(catalogNum-freezeCatalogInfo2.getFreezeNum()-activityStock2, num2, "验证规格库存");
			//验证冻结表库存
			Integer freezeNum1 = new YmtProductFreezeStockWapper().selectByProductId(productId).get(0).getFreezeNum();
			Logger.verifyEquals(freezeCatalogInfo1.getFreezeNum(),freezeNum1, "验证冻结表库存");
			Integer freezeNum2 = new YmtProductFreezeStockWapper().selectByProductId(productId).get(1).getFreezeNum();
			Logger.verifyEquals(freezeCatalogInfo2.getFreezeNum(),freezeNum2, "验证冻结表库存");
			
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_FreezeAllocateStock_006() {
		Logger.start(true,"不传冻结数量参数或者冻结参数为负数时");
		try {
			/**
			 * 传库存参数为负数时：
			 * "Code":201,"Msg":"错误的请求参数|freezeNum must","Data":null"Code":201,"Msg":"错误的请求参数|freezeNum must","Data":null
			 * 不传库存参数时：
			 * 冻结表有记录，冻结库存为0
			 */
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			String freezeId = "JD18628";
			freezeallocatestockBean.setActivityId(activityId);
			freezeallocatestockBean.setFreezeId(freezeId);
			freezeallocatestockBean.setFreezeType(0);
			freezeallocatestockBean.setIsFbxProduct(false);
			freezeallocatestockBean.setProductInActivityId(Integer.valueOf(aids.get(0)));
			freezeallocatestockBean.setProductID(productId);
			freezeallocatestockBean.setStoreType(-1);
			freezeallocatestockBean.setUserID(sellerId);
			FreezeCatalogInfo freezeCatalogInfo = new FreezeCatalogInfo();
			freezeCatalogInfo.setCatalogId(catalogs.get(0));
			//freezeCatalogInfo.setFreezeNum(-100);
			
			freezeCatalogInfo.setSku(null);
			FreezeCatalogList.add(freezeCatalogInfo);
			freezeallocatestockBean.setFreezeCatalogList(FreezeCatalogList);
			freezeallocatestockCall.setData(freezeallocatestockBean);
			freezeallocatestockCall.callService();
			String Code = freezeallocatestockCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	/*@Test
	@Category({P2.class})
	@TestCase
	public void Tc_FreezeAllocateStock_007() {
		Logger.start(true,"活动商品，不同规格，一个规格参与活动，一个规格为参与活动，冻结");
		try {
			*//**
			 * 两种规格都添加到冻结表中
			 *//*
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			String catalog0 = catalogs.remove(0);
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			String freezeId = "JD18628";
			freezeallocatestockBean.setActivityId(activityId);
			freezeallocatestockBean.setFreezeId(freezeId);
			freezeallocatestockBean.setFreezeType(0);
			freezeallocatestockBean.setIsFbxProduct(false);
			freezeallocatestockBean.setProductInActivityId(Integer.valueOf(aids.get(0)));
			freezeallocatestockBean.setProductID(productId);
			freezeallocatestockBean.setStoreType(-1);
			freezeallocatestockBean.setUserID(sellerId);
			FreezeCatalogInfo freezeCatalogInfo1 = new FreezeCatalogInfo();
			freezeCatalogInfo1.setCatalogId(catalogs.get(0));
			freezeCatalogInfo1.setFreezeNum(100);
			freezeCatalogInfo1.setSku(null);
			FreezeCatalogInfo freezeCatalogInfo2 = new FreezeCatalogInfo();
			freezeCatalogInfo2.setCatalogId(catalog0);
			freezeCatalogInfo2.setFreezeNum(200);
			freezeCatalogInfo2.setSku(null);
			FreezeCatalogList.add(freezeCatalogInfo1);
			FreezeCatalogList.add(freezeCatalogInfo2);
			freezeallocatestockBean.setFreezeCatalogList(FreezeCatalogList);
			freezeallocatestockCall.setData(freezeallocatestockBean);
			freezeallocatestockCall.callService();
			String Code = freezeallocatestockCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			
			FreezeProductResult productResult1 = freezeallocatestockCall.getResults().get(0);
			Logger.verifyEquals(activityId, productResult1.getActivityId(), "验证活动编号");
			Logger.verifyEquals(productId, productResult1.getProductId(), "验证商品编号");
			Logger.verifyEquals(catalogs.get(0), productResult1.getCatalogId(), "验证规格编号");
			Logger.verifyEquals(freezeId, productResult1.getFreezeId(), "验证冻结编号");
			Logger.verifyEquals(aids.get(0), productResult1.getProductInActivityId().toString(), "验证商品在活动中的编号");
			FreezeProductResult productResult2 = freezeallocatestockCall.getResults().get(1);
			Logger.verifyEquals(activityId, productResult2.getActivityId(), "验证活动编号");
			Logger.verifyEquals(productId, productResult2.getProductId(), "验证商品编号");
			Logger.verifyEquals(catalog0, productResult2.getCatalogId(), "验证规格编号");
			Logger.verifyEquals(freezeId, productResult2.getFreezeId(), "验证冻结编号");
			Logger.verifyEquals(aids.get(0), productResult2.getProductInActivityId().toString(), "验证商品在活动中的编号");
			
			//验证规格库存
			Integer num1 = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Integer activityStock1 = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(catalogNum-freezeCatalogInfo1.getFreezeNum()-activityStock1, num1, "验证规格库存");
			
			Integer num2 = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(1).getiNum();
			Logger.verifyEquals(catalogNum-freezeCatalogInfo2.getFreezeNum(), num2, "验证规格库存");
			
			//验证活动柜库存
			Integer freezeNum1 = new YmtProductFreezeStockWapper().selectByProductId(productId).get(0).getFreezeNum();
			Logger.verifyEquals(freezeCatalogInfo1.getFreezeNum(),freezeNum1, "验证冻结表库存");
			
			Integer freezeNum2 = new YmtProductFreezeStockWapper().selectByProductId(productId).get(1).getFreezeNum();
			Logger.verifyEquals(freezeCatalogInfo2.getFreezeNum(),freezeNum2, "验证冻结表库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});						
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_FreezeAllocateStock_008() {
		Logger.start(true,"活动商品，不是活动规格申请冻结");
		try {
			*//**
			 * 依旧还会在冻结表中
			 *//*
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			String catalog0 = catalogs.remove(0);
			Logger.debug(catalog0);
			Logger.debug(catalogs.get(0));
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			String freezeId = "JD18628";
			freezeallocatestockBean.setActivityId(activityId);
			freezeallocatestockBean.setFreezeId(freezeId);
			freezeallocatestockBean.setFreezeType(0);
			freezeallocatestockBean.setIsFbxProduct(false);
			freezeallocatestockBean.setProductInActivityId(Integer.valueOf(aids.get(0)));
			freezeallocatestockBean.setProductID(productId);
			freezeallocatestockBean.setStoreType(-1);
			freezeallocatestockBean.setUserID(sellerId);
			FreezeCatalogInfo freezeCatalogInfo = new FreezeCatalogInfo();
			freezeCatalogInfo.setCatalogId(catalog0);
			freezeCatalogInfo.setFreezeNum(100);
			freezeCatalogInfo.setSku(null);
			FreezeCatalogList.add(freezeCatalogInfo);
			freezeallocatestockBean.setFreezeCatalogList(FreezeCatalogList);
			freezeallocatestockCall.setData(freezeallocatestockBean);
			freezeallocatestockCall.callService();
			String Code = freezeallocatestockCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			
			freezeallocatestockCall.getResults().forEach(pp->{
				Logger.verifyEquals(activityId, pp.getActivityId(), "验证活动编号");
				Logger.verifyEquals(productId, pp.getProductId(), "验证商品编号");
				Logger.verifyEquals(catalog0, pp.getCatalogId(), "验证规格编号");
				Logger.verifyEquals(freezeId, pp.getFreezeId(), "验证冻结编号");
				Logger.verifyEquals(aids.get(0), pp.getProductInActivityId().toString(), "验证商品在活动中的编号");
			});
			
			//验证规格库存
			Integer num = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Integer activityStock = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(catalogNum-freezeCatalogInfo.getFreezeNum(), num, "验证规格库存");
			//验证冻结表库存
			Integer freezeNum = new YmtProductFreezeStockWapper().selectByProductId(productId).get(0).getFreezeNum();
			Logger.verifyEquals(freezeCatalogInfo.getFreezeNum(),freezeNum, "验证冻结表库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}*/
}